var BSTMG = BSTMG || {};
BSTMG.payment = {
		init: function(){
			var that = this;
			//线下支付列表查询 
			that.paymentListReq();
			//分页功能
			
		},
		paymentListReq: function(){
			$.ajax({
				type : "POST",
				url : "/payment/paymentList/search",
				async : false,
				success:function(data){
					var paymentList = data.paymentList;
					var $tbody = $("#paymentList tbody");
					if(paymentList.length > 0) {
						for(var i=0;i<paymentList.length;i++){
							var paymentInfo = paymentList[i];
							var remitTime;
							if(paymentInfo.remitTime){
								remitTime = new Date(paymentInfo.remitTime);
								remitTime = toDate(remitTime, "yyyy-MM-dd hh:mm:ss");
							}else{
								remitTime = '';
							}
								
							var $tr = '<tr class="odd">';
							$tr += '<td>'+paymentInfo.paymentNum+'</td>';
							$tr += '<td>'+setDealType(paymentInfo.dealType)+'</td>';
							$tr += '<td>'+checkNull(paymentInfo.remitCompany)+'</td>';
							$tr += '<td>'+checkNull(paymentInfo.remitBank)+'</td>';
							$tr += '<td>'+checkNull(paymentInfo.remitMoney)+'</td>';
							$tr += '<td>'+remitTime+'</td>';
							$tr += '<td>'+setPaymentType(paymentInfo.paymentState)+'</td>';
							$tr += '<td><a class="btn btn-primary" href="/payment/paymentDetail/'+paymentInfo.paymentId+'">'+setPaymentButton(paymentInfo.paymentState)+'</a></td>';
							$tr += '</tr>';
							$tbody.append($tr);
						}
					}else {
						var $tr = '<tr class="odd"><td colspan="8">暂无数据！</td></tr>';
						$tbody.append($tr);
						BSTYUN.dialog.warn("查询失败！");
					}
				},
				error: function(){
					BSTYUN.dialog.warn("网络异常!请稍后尝试操作");
				}
			})
		}
}

$(function(){
	BSTMG.payment.init();
});


//审核操作
function toAudit(paymentId,paymentState){
	$.ajax({
		type : "POST",
		url : "/payment/updatePayment",
		async : false,
		data:{
			paymentId:paymentId,
			paymentState:paymentState
		},
		success:function(data){
			if(data) alert("审核成功！");
			else alert("审核失败！");
		}
	})
}

//检测非空
function checkNull(para){
	if(para == null){
		return "";
	}else{
		return para;
	}
}

//设置交易类型
function setDealType(dealType){
	if (dealType == "1") {
		return "充值";
	} else if (dealType == "2") {
		return "消费";
	} else if (dealType == "3") {
		return "提现";
	} else if (dealType == "4") {
		return "退款";
	} else if (dealType == "5") {
		return "其他";
	}
}

//设置凭证上传状态
function setPaymentType(para){
	if (para == "0") {
		return "未上传";
	} else if (para == "1") {
		return "已上传";
	} else if(para == "2"){
		return "审核通过";
	} else if(para == "3"){
		return "审核退回";
	}
}

//设置操作按钮
function setPaymentButton(para){
	if (para == "0") {
		return "等待上传";
	} else if (para == "1") {
		return "待审核";
	} else if(para == "2"){
		return "审核通过";
	} else if(para == "3"){
		return "退回待审核";
	}
}




